//
//  RightSearchController.m
//  quickLook
//
//  Created by J on 15/8/30.
//  Copyright (c) 2015年 JZJ. All rights reserved.
//

#import "RightSearchController.h"

#import "CollectionViewCell.h"

#import "Header.h"
#import "SecondSearchController.h"
#import "RightCollectionClickController.h"
#import "ThridSearchController.h"
#define ID @"CollectionViewCell"


@interface RightSearchController ()<UISearchBarDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
{

    NSInteger _number;

}
@property(nonatomic,strong)UICollectionView* collectionView;

@property(nonatomic,strong)NSArray* titlesArr;

@property(nonatomic,strong)NSMutableArray* dataArr;



@end

@implementation RightSearchController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self createUI];

    
    UINib *nib=[UINib nibWithNibName:@"CollectionViewCell" bundle:nil];
    [self.collectionView registerNib:nib forCellWithReuseIdentifier:ID];
    
    _number=0;
    

}

- (void)createUI
{
    
    
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(pop)];
    
    
    self.view.backgroundColor=[UIColor whiteColor];
    
    
    //加上 搜索栏
//    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 35)];//allocate titleView
//    UIColor *color =  self.navigationController.navigationBar.barTintColor;
    
//    [titleView setBackgroundColor:color];
    
    UISearchBar *searchBar = [[UISearchBar alloc] init];
    
 
    
    searchBar.delegate = self;
    searchBar.frame = CGRectMake(0, 0, 200, 30);
//    searchBar.backgroundColor = color;
//    searchBar.layer.cornerRadius = 25;
    searchBar.layer.masksToBounds = YES;
    [searchBar.layer setBorderWidth:0];
    [searchBar.layer setBorderColor:[UIColor whiteColor].CGColor];  //设置边框为白色
    
    searchBar.placeholder = @"|搜索作品名、 作者名";
//    [titleView addSubview:searchBar];
    
    //Set to titleView
//    [self.navigationItem.titleView sizeToFit];
    self.navigationItem.titleView = searchBar;
    
  /**
     *  分割线
     */


    _titlesArr=@[@"HOT",@"优秀新连载",@"已完结",@"少女",@"爆笑",@"耽美",@"百合",@"恐怖",@"剧情",@"三次元",@"日常",@"悬疑",@"治愈",@"奇幻"];
    
    
    
    
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc]init];
    
    flowLayout.itemSize=CGSizeMake(100, 120);
    //
    flowLayout.minimumLineSpacing=5;
    flowLayout.minimumInteritemSpacing=3;
    
    
    flowLayout.sectionInset=UIEdgeInsetsMake(flowLayout.minimumLineSpacing, flowLayout.minimumInteritemSpacing, flowLayout.minimumInteritemSpacing, flowLayout.minimumInteritemSpacing);
    
    

    
    _collectionView = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:flowLayout];
    
    self.view.backgroundColor=[UIColor whiteColor];
    _collectionView.backgroundColor=[UIColor whiteColor];
    _collectionView.delegate=self;
    _collectionView.dataSource=self;
    [self.view addSubview:_collectionView];
  
}



#pragma mark --UICollectionViewDataSource


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    
    
    RightCollectionClickController* vc=[[RightCollectionClickController alloc]init];
    
    
    NSString* title=_titlesArr[indexPath.item];
    vc.navigationTitle=title;
//    JZJLog(@"%@",title);
    
    
    [self.navigationController pushViewController:vc animated:YES];

   
    


}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    
    
    return 14;
    
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    CollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    UIImage* image= [UIImage imageNamed:[NSString stringWithFormat:@"%zd.png",indexPath.item]];
    NSString* title=_titlesArr[indexPath.item];
    [cell refreshWithArray:title andImage:image];

    return cell;

    
}


- (void)pop {
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    SecondSearchController* vc=[[SecondSearchController alloc]init];
    [self.navigationController pushViewController:vc animated:NO];

}










@end
